package enumliteralisunique;

import java.util.Arrays;
import org.eclipse.viatra2.emf.incquery.runtime.api.IPatternMatch;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BasePatternMatch;
import org.eclipse.viatra2.patternlanguage.core.patternLanguage.Pattern;
import sysmodel.Enumeration;
import sysmodel.Literal;

/**
 * Pattern-specific match representation of the EnumLiteralIsUnique pattern, 
 * to be used in conjunction with EnumLiteralIsUniqueMatcher.
 * 
 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
 * Each instance is a (possibly partial) substitution of pattern parameters, 
 * usable to represent a match of the pattern in the result of a query, 
 * or to specify the bound (fixed) input parameters when issuing a query.
 * 
 * @see EnumLiteralIsUniqueMatcher
 * @see EnumLiteralIsUniqueProcessor
 * 
 */
public final class EnumLiteralIsUniqueMatch extends BasePatternMatch implements IPatternMatch {
  private Enumeration fEnumeration;
  
  private Literal fLiteral;
  
  private Literal fLiteral2;
  
  private static String[] parameterNames = {"enumeration", "literal", "literal2"};
  
  public EnumLiteralIsUniqueMatch(final Enumeration pEnumeration, final Literal pLiteral, final Literal pLiteral2) {
    this.fEnumeration = pEnumeration;
    this.fLiteral = pLiteral;
    this.fLiteral2 = pLiteral2;
    
  }
  
  @Override
  public Object get(final String parameterName) {
    if ("enumeration".equals(parameterName)) return this.fEnumeration;
    if ("literal".equals(parameterName)) return this.fLiteral;
    if ("literal2".equals(parameterName)) return this.fLiteral2;
    return null;
    
  }
  
  public Enumeration getEnumeration() {
    return this.fEnumeration;
    
  }
  
  public Literal getLiteral() {
    return this.fLiteral;
    
  }
  
  public Literal getLiteral2() {
    return this.fLiteral2;
    
  }
  
  @Override
  public boolean set(final String parameterName, final Object newValue) {
    if ("enumeration".equals(parameterName) && newValue instanceof sysmodel.Enumeration) {
    	this.fEnumeration = (sysmodel.Enumeration) newValue;
    	return true;
    }
    if ("literal".equals(parameterName) && newValue instanceof sysmodel.Literal) {
    	this.fLiteral = (sysmodel.Literal) newValue;
    	return true;
    }
    if ("literal2".equals(parameterName) && newValue instanceof sysmodel.Literal) {
    	this.fLiteral2 = (sysmodel.Literal) newValue;
    	return true;
    }
    return false;
    
  }
  
  public void setEnumeration(final Enumeration pEnumeration) {
    this.fEnumeration = pEnumeration;
    
  }
  
  public void setLiteral(final Literal pLiteral) {
    this.fLiteral = pLiteral;
    
  }
  
  public void setLiteral2(final Literal pLiteral2) {
    this.fLiteral2 = pLiteral2;
    
  }
  
  @Override
  public String patternName() {
    return "EnumLiteralIsUnique";
    
  }
  
  @Override
  public String[] parameterNames() {
    return EnumLiteralIsUniqueMatch.parameterNames;
    
  }
  
  @Override
  public Object[] toArray() {
    return new Object[]{fEnumeration, fLiteral, fLiteral2};
    
  }
  
  @Override
  public String prettyPrint() {
    StringBuilder result = new StringBuilder();
    result.append("\"enumeration\"=" + prettyPrintValue(fEnumeration) + ", ");
    
    result.append("\"literal\"=" + prettyPrintValue(fLiteral) + ", ");
    
    result.append("\"literal2\"=" + prettyPrintValue(fLiteral2)
    );return result.toString();
    
  }
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((fEnumeration == null) ? 0 : fEnumeration.hashCode()); 
    result = prime * result + ((fLiteral == null) ? 0 : fLiteral.hashCode()); 
    result = prime * result + ((fLiteral2 == null) ? 0 : fLiteral2.hashCode()); 
    return result; 
    
  }
  
  @Override
  public boolean equals(final Object obj) {
    if (this == obj)
    	return true;
    if (obj == null)
    	return false;
    if (!(obj instanceof IPatternMatch))
    	return false;
    IPatternMatch otherSig  = (IPatternMatch) obj;
    if (!pattern().equals(otherSig.pattern()))
    	return false;
    if (!EnumLiteralIsUniqueMatch.class.equals(obj.getClass()))
    	return Arrays.deepEquals(toArray(), otherSig.toArray());
    				EnumLiteralIsUniqueMatch other = (EnumLiteralIsUniqueMatch) obj;
    				if (fEnumeration == null) {if (other.fEnumeration != null) return false;}
    				else if (!fEnumeration.equals(other.fEnumeration)) return false;
    				if (fLiteral == null) {if (other.fLiteral != null) return false;}
    				else if (!fLiteral.equals(other.fLiteral)) return false;
    				if (fLiteral2 == null) {if (other.fLiteral2 != null) return false;}
    				else if (!fLiteral2.equals(other.fLiteral2)) return false;
    				return true;
    
  }
  
  @Override
  public Pattern pattern() {
    return EnumLiteralIsUniqueMatcher.FACTORY.getPattern();
  }
}
